/*
 * @Author: intellectual-seeker 3336339701@qq.com
 * @Date: 2025-09-01 10:37:11
 * @LastEditors: intellectual-seeker 3336339701@qq.com
 * @LastEditTime: 2025-09-01 10:41:18
 * @FilePath: /code/lesson32/LockGuard.hpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#ifndef LOCK_GUARD_HPP
#define LOCK_GUARD_HPP
#include <pthread.h>

//RAII方式设计锁
class LockGuard
{
public:
    LockGuard(pthread_mutex_t* pmutex)
        :_pmutex(pmutex)
    {
        pthread_mutex_lock(_pmutex);
    }

    ~LockGuard()
    {
        pthread_mutex_unlock(_pmutex);
    }


private:
    pthread_mutex_t* _pmutex;
};

#endif